Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: Allow watchers without an ecto schema #18

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

cheerfulstoic
Copy link
Owner

@cheerfulstoic cheerfulstoic commented Aug 1, 2024

Fixes #16

From the new README section:


Watching without a schema

Since ecto supports working with tables withoun needed a schema, you may also want to create EctoWatch watchers without needing to create a schema like so:

  # setup
  {EctoWatch,
   repo: MyApp.Repo,
   pub_sub: MyApp.PubSub,
   watchers: [
    {
      %{
        table_name: "comments",
        primary_key: "ID",
        columns: [:title, :body, :author_id, :post_id],
        association_columns: [:author_id, :post_id]
      }, :updated, extra_columns: [:post_id]
    }
   ]}

Everything works the same as with a schema, though make sure to specify your association columns if you want to subscribe to an association column.

Supported keys for configuring a table without a schema:

  • pg_schema_name (optional, defaults to public)
  • table_name (required)
  • primary_key (optional, defaults to id)
  • columns (optional, defaults to [])
  • association_columns (optional, defaults to [])

@cheerfulstoic cheerfulstoic force-pushed the allow-schemaless-config branch 5 times, most recently from 6e8c35b to 77cfa18 Compare August 2, 2024 09:11
@cheerfulstoic cheerfulstoic marked this pull request as ready for review August 2, 2024 09:12
@cheerfulstoic cheerfulstoic force-pushed the allow-schemaless-config branch 2 times, most recently from 77a43f5 to 93f2b16 Compare August 2, 2024 09:47
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lib/ecto_watch/options/watcher_options.ex Show resolved Hide resolved
lib/ecto_watch/watcher_server.ex Outdated Show resolved Hide resolved
@cheerfulstoic cheerfulstoic force-pushed the allow-schemaless-config branch 2 times, most recently from 4e2c9ee to d9818f9 Compare August 2, 2024 11:24
@cheerfulstoic cheerfulstoic force-pushed the allow-schemaless-config branch from d9818f9 to 067ab40 Compare August 2, 2024 11:26
@cheerfulstoic cheerfulstoic merged commit f08acca into main Aug 2, 2024
1 check passed
@cheerfulstoic cheerfulstoic deleted the allow-schemaless-config branch August 2, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permit watching tables without requiring schemas.
2 participants